﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace CopyDirectory
{
    class Copy
    {
        public static void CopyDir(string sourceDir, string endDir) 
        {
            Directory.CreateDirectory(endDir);
            string[] files = Directory.GetFiles(sourceDir);
            string[] directories = Directory.GetDirectories(sourceDir);
            foreach (var file in files)
            {
                string fileonlyname = file.Substring(file.LastIndexOf(@"\"));
                File.Copy(file, endDir + fileonlyname);
            }
            foreach (var dir in directories)
            {
                string dirOnlyName = dir.Substring(dir.LastIndexOf("\\"));
                CopyDir(dir, endDir+dirOnlyName);
            }
        }

        static void Main(string[] args)
        {
            string sourceDirectory = @"D:\CodeplexRepository\Panayot Popov\InputOutput\InputOutput\SearchForString\pesho";
            string endDirectory = @"C:\peshoCopied";
            CopyDir(sourceDirectory, endDirectory);

        }
    }
}
